<!--
 * @Author: Lin Ming
 * @Date: 2021-02-23 23:16:36
 * @LastEditors: Lin Ming
 * @LastEditTime: 2021-02-23 23:47:16
 * @FilePath: \vue-zheye\src\components\Dropdown.vue
-->
<template>
  <div class="lm-drop-down">
    <div class="dropdown">
      <!-- @click.prevent  防止默认行为 -->
      <a class="btn btn-outline-light my-2 dropdown-toggle" href="#" @click.prevent="toggleOpen">{{title}}</a>
      <ul class="dropdown-menu" aria-labelledby="dropdownMenuLink" :style="{display: 'block'}" v-if="isOpen">
        <slot />
      </ul>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
export default defineComponent({
  name: 'Dropdown',
  props: {
    title: {
      type: String,
      required: true
    }
  },
  setup () {
    const isOpen = ref(false)
    const toggleOpen = () => {
      isOpen.value = !isOpen.value
    }
    return {
      isOpen,
      toggleOpen
    }
  }
})
</script>
